package com.leyou.order.scheduling;

import com.leyou.order.entity.Order;
import com.leyou.order.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 订单定时任务类
 */
@Slf4j
@Component
public class OrderScheduling {

    @Autowired
    private OrderService orderService;

    /**
     * 定时清除失效订单
     *          20分钟不支付:归还库存, 状态为支付过期
     *          2小时没支付: 状态为 已失效
     */
    @Scheduled(cron = "0/10 * * * * ?")  //一分钟检测一次
    public void failureOrderClearJob(){
        //查询失效订单集合  >20
        List<Order> failureOrder = orderService.findFailureOrder();
        /*修改失效订单状态
                超时20分钟-- 7
                超时2小时 -- 8
         */
        orderService.changeStatus(failureOrder);
        System.out.println(failureOrder);
        log.info("清除失效订单定时任务执行了！");
    }

}
